package com.powernode.settings.controller;

import com.powernode.commons.utils.ResponseData;
import com.powernode.settings.bean.DicValueBean;
import com.powernode.settings.service.DicValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("value")
@Api(tags = "字典值维护")
public class DicValueController {
    @Resource
    private DicValueService service;


    @GetMapping
    @ApiOperation("分页获取所有的字典值")
    public ResponseData getAll(@RequestParam(required = false,defaultValue = "1") Integer pageNumber,
                               @RequestParam(required = false,defaultValue = "5") Integer pageSize,
                               String typeCode){
        return service.findAll(pageNumber,pageSize,typeCode);
    }

    @PostMapping
    @ApiOperation("添加字典值")
    public ResponseData add(@RequestBody DicValueBean value){
        return service.add(value);
    }

    @PutMapping
    @ApiOperation("修改字典值")
    public ResponseData edit(@RequestBody DicValueBean val){
        return service.modify(val);
    }

    @DeleteMapping
    @ApiOperation("删除字典值")
    public ResponseData delete(@ApiParam("根据主键id删除,如果有多个用逗号拼接") String ids){
        return service.removeBatch(ids);
    }

    @GetMapping("getDicValueByCode")
    @ApiOperation("根据字典类型查询字典值")
    public ResponseData getDicValueByCode(String code){
        return service.findByCode(code);
    }
}
